package logicaDeNegocios;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

public class Busqueda {
	final  String CONTROLADOR ="com.mysql.jdbc.Driver";
	final  String URL_BASEDATOS = "jdbc:mysql://localhost/pos";
	private Connection conexion;
	
	public Vector< Vector<Object> > obtenerDatos(String consulta)	
	{
		Vector< Vector<Object> > datos = new Vector<>();
		
		try 
        {
        	try 
        	{
        		Class.forName(CONTROLADOR);
			} 
        	catch (ClassNotFoundException e) 
        	{
				e.printStackTrace();
        	}
           
            conexion = DriverManager.getConnection(URL_BASEDATOS, "root", "");
			Statement st = conexion.createStatement();
            ResultSet rs = st.executeQuery(consulta);

            while(rs.next())
            {
            	Vector registros = new Vector<Object>(); 
            	for (int i = 0; i < rs.getMetaData().getColumnCount(); i++)
				{
            		registros.add(rs.getObject(i+1));
				}
                datos.add(registros);                  
            }
           return datos;
        }
        catch (SQLException ex)
        {
        	return datos;
        }	
	}
}